package cn.liumouren.task;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 每天3点清理excel
 */
@Component
public class CleanExcel {

    @Value("${excels.path}")
    private String path; //储存excels的路径

    // 每天凌晨三点清理一次excels文件夹
    @Scheduled(cron = "0 0 3 * * ?")
    public void cleanExcel() {
        try {
            FileUtil.del(path);
            FileUtil.mkdir(path);
            System.out.println("已删除" + path + "下的所有文件");
        } catch (IORuntimeException e) {
            FileUtil.mkdir(path);
        }
    }
}
